home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hackers Handbook - Millenium Edition
/
Hackers Handbook.iso
/
files
/
c_scripts
/
spider.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-12-05
|
3KB
|
145 lines
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
typedef struct dir_node
{
char name[256];
struct dir_node *next;
}_dir_node;
typedef struct file_node
{
char name[256];
struct file_node *next;
}_file_node;
struct dir_node *dir_ll = NULL;
struct file_node *file_ll = NULL;
void add_dir(char *dir_to_add)
{
struct dir_node *new_node, *cur_node = dir_ll;
new_node = (struct dir_node*)calloc(sizeof(struct dir_node),1);
sprintf(new_node->name,"%s",dir_to_add);
new_node->next = NULL;
if(cur_node == NULL)
{
dir_ll = new_node;
return;
}
while(cur_node->next)
cur_node = cur_node->next;
cur_node->next = new_node;
}
void add_file(char *file_to_add)
{
struct file_node *new_node, *cur_node = file_ll;
char *str_ptr;
int i,length = strlen(file_to_add);
for(i=length-1;i>0;i--)
{
if(file_to_add[i] == '.')
{
str_ptr = &(file_to_add[i]);
if(!strcmp(str_ptr,".html"))
break;
else
return;
}
}
if(i<0||i==0)
return;
new_node = (struct file_node*)calloc(sizeof(struct file_node),1);
sprintf(new_node->name,"%s",file_to_add);
new_node->next = NULL;
if(cur_node == NULL)
{
file_ll = new_node;
return;
}
while(cur_node->next)
cur_node = cur_node->next;
cur_node->next = new_node;
}
void split_dir(char *dir_name)
{
DIR *base_dir, *test_dir;
struct dirent *entry;
char *filename,complete_path[128];
if(!dir_name || !*dir_name)
return;
if(!(base_dir = opendir(dir_name)))
return;
while(entry = readdir(base_dir))
{
filename = entry->d_name;
sprintf(complete_path,"%s/%s",dir_name,filename);
if(!strcmp(".",filename)||!strcmp("..",filename))
continue;
test_dir = opendir(complete_path);
if(test_dir)
{
add_dir(complete_path);
closedir(test_dir);
}
else
{
add_file(complete_path);
}
}
closedir(base_dir);
}
void main(int argc, char* argv[])
{
struct dirent *dir_entry,*test_entry;
DIR *base_dir,*test_dir;
struct dir_node *dir_ent;
struct file_node *file_ent;
char string[256];
if(!(base_dir = opendir("/home2")))
return;
while(dir_entry = readdir(base_dir))
{
sprintf(string,"/home2/%s/my_html",dir_entry->d_name);
if(test_dir = opendir(string))
{
split_dir(string);
closedir(test_dir);
}
}
closedir(base_dir);
while(dir_ll)
{
dir_ent = dir_ll;
dir_ll = dir_ll->next;
split_dir(dir_ent->name);
free(dir_ent);
}
while(file_ll)
{
file_ent = file_ll;
printf("%s\n",file_ent->name);
file_ll = file_ll->next;
free(file_ent);
}
}